@extends('../manage.layout')
@section('content')
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            内容管理
            <small></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
            <li class="active">Here</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <form method="post" id="form" name="form">{{ csrf_field() }}
                <!-- general form elements -->
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            <a href="javascript:batchdelSub()"><span class="btn btn-danger">批量删除</span></a> <input type="button" class="btn btn-primary" value="批量导出" onclick="batchexport()"> <a href="/manage/article/create" type="submit" class="btn btn-success"><i class="fa fa-pencil"></i> 添加文章</a>
                        </div>
                        <!-- table start -->
                        <div class="row">

                            <div class="col-xs-12">
                                <div class="box">
                                    <div class="box-header">
                                        <h3 class="box-title">查询结果</h3>

                                        <div class="box-tools">
                                            <div class="input-group input-group-sm" style="width: 150px;">
                                                <select class="form-control pull-right"  name="category" id="category" style="position:absolute; right:410px;">
                                                    <option value="">请选择</option>
                                                    @foreach($categorys as $category)
                                                        @if ($sear_cate == $category->id)
                                                            <option value="{{ $category->id }}" selected>{{ $category->name }}</option>
                                                        @else
                                                        <option value="{{ $category->id }}">{{ $category->name }}</option>
                                                        @endif
                                                    @endforeach
                                                </select>
                                                <input type="text" name="create_time" class="form-control pull-right" id="reservation" style="position:absolute; right: 296px;" value="{{ $sear_time }}">
                                                <input type="text" name="keyword" class="form-control pull-right" placeholder="关键词" style="position:absolute; right:148px" value="{{ $sear_keyw }}">
                                                <input type="text" name="table_search" class="form-control pull-right" placeholder="标题" value="{{ $sear_titl }}">

                                                <div class="input-group-btn">
                                                    <button type="button" class="btn btn-default" onclick="seach()"><i class="fa fa-search"></i></button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- /.box-header -->
                                    <div class="box-body table-responsive no-padding">
                                        <table class="table table-hover" id="table">
                                            <tr>
                                                <th><input type="checkbox" value="" onclick="selectAll(this)"></th>
                                                <th>ID</th>
                                                <th>标题</th>
                                                <th>分类</th>
                                                <th>关键词</th>
                                                <th>导读图</th>
                                                <th>创建时间</th>
                                                <th>更新时间</th>
                                                <th>操作</th>
                                            </tr>
                                            <script>
                                                function selectAll(obj) {
                                                    $("#table input[type='checkbox']").prop('checked', $(obj).prop('checked'));
                                                }
                                            </script>
                                            @if(!$result->all())
                                                <tr>
                                                    <td colspan="9" style="text-align:center"><h1>空</h1></td>
                                                </tr>
                                            @endif
                                            @foreach($result as $article)
                                                <tr>
                                                    <td><input name="chkbox[]" type="checkbox" value="{{ $article->id }}"></td>
                                                    <td>{{ $article->id }}</td>
                                                    <td>{{ $article->title }}</td>
                                                    @foreach($categorys as $category)
                                                        @if($article->category == $category->id)
                                                            <td>{{ $category->name }}</td>
                                                        @endif
                                                    @endforeach
                                                    <td>{{ $article->keyword }}</td>
                                                    <td><a href="/upload/{{ $article->file }}" target="_blank"><img src="/upload/{{ $article->file }}" width="30" height="30" /></a></td>
                                                    <td>{{ $article->create_time }}</td>
                                                    <td>{{ $article->update_time }}</td>
                                                    <td width="180">
                                                        @if($article->status == 1)
                                                            <a href="/manage/artibatcstatus/{{ $article->id }}"><span class="label label-success">启用</span></a>
                                                        @else
                                                            <a href="/manage/artibatcstatus/{{ $article->id }}"><span class="label bg-orange">禁用</span></a>
                                                        @endif
                                                        &nbsp;
                                                        <a href="/manage/article/{{ $article->id }}/edit"><span class="label label-primary">更改</span></a>&nbsp;
                                                        <a href="javascript:delSubscribe({{ $article->id }})"><span class="label label-danger">删除</span></a></td>

                                                </tr>
                                            @endforeach
                                        </table>
                                    </div>
                                    <!-- /.box-body -->
                                </div>
                                <!-- /.box -->
                            </div>

                        </div>
                        <!-- /.table -->
                        {{--<div style="text-align: center">{{ $result->links() }}</div>--}}

                    </div>
                </form>
            </div>
        </div>
    </section>
    <!-- /.content -->
@endsection
@section('script')
    <script type="text/javascript">
        $('#reservation').daterangepicker();
    </script>
@endsection
<script>
    function delSubscribe(id) {
        layer.confirm('删除不可恢复，是否继续？', {
            btn:['确定','取消'] //按钮
        }, function() {
            $.post("{{ url('manage/article/') }}/"+id,{'_method':'delete','_token':"{{ csrf_token() }}"},function(data){
                if(data.status==0) {
                    layer.msg(data.msg, {time:1500, icon:5});
                } else {
                    layer.msg(data.msg, {time:1500, icon:6});
                    window.location.href = "/manage/article/";
                }
            });
        }, function() {

        });
    }

    function batchdelSub() {
        /*var data = [];
         var ckb = document.getElementsByName('chkbox[]');
         for(var i = 0; i < ckb.length; i++) {
         if(ckb[i].checked) {
         data.push(ckb[i].value);
         }
         }*/
        layer.confirm('删除不可恢复，是否继续？', {
            btn:['确定','取消'] //按钮
        }, function() {
            $.ajax({
                url: "/manage/artibatcdel/",
                type: "POST",
                data: $('#form').serialize(),
                success: function (data) {
                    layer.msg(data.msg, {time:1500, icon:6});
                },
                error: function (data) {
                    layer.msg(data.msg, {time:1500, icon:5});
                }
            });
        });
    }

    // 查询
    function seach() {
        document.form.action="/manage/artibatcserc/";
        document.form.submit();
    }
    // 导出
    function batchexport() {
        document.form.action="/manage/aritbatcexport/";
        document.form.submit();
    }


</script>